package org.dey.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.dey.pojo.User;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author deyran
 * @classname
 * @see BaseMapper
 */
@Repository
public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT * FROM t_user")
    @Results(id = "org.dey.mapper.UserMapper",value = {
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "birthday",property = "birthday"),
            @Result(column = "gender",property = "gender"),
            @Result(column = "username",property = "username"),
            @Result(column = "password",property = "password"),
            @Result(column = "remark",property = "remark"),
            @Result(column = "station",property = "station"),
            @Result(column = "telephone",property = "telephone"),
            @Result(property = "roles",column = "id",many = @Many(select = "org.dey.mapper.org.dey.mapper.RoleMapper.ROLE_ID"))
    })
    @Lazy(false)
    List<User> USERS();

    @Select("select COUNT(*) from `t_user_role` where user_id =#{userid} and role_id = #{roleid} ")
    int queryrole(@Param("userid") int userid,@Param("roleid") int roleid);

    @Insert("INSERT INTO `t_user_role` VALUES(#{userid},#{roleid})")
    int addroleqq(@Param("userid") int userid,@Param("roleid") int roleid);


}
